package com.wjk.kylin.id.core.spring.boot.autoconfigure.uid;

import org.springframework.boot.context.properties.ConfigurationProperties;


/**
 * @author wjk
 */
@ConfigurationProperties(prefix = "kylin.id.uid")
public class UIdProperties {
    /**
     * 是否启动rpc 服务消费者，默认不启用
     */
    private boolean enable = false;
    /**
     * 初始时间 默认 2022-09-10
     */
    private String epochStr = "2022-10-01";
    /**
     * 时间位, 默认:31 。68年
     */
    private int timeBits = 31;
    /**
     * 机器位, 默认:22 。420万次
     */
    private int workerBits = 22;
    /**
     * 序列号 默认 10 。1024并发
     */
    private int seqBits = 10;

    /**
     * biz_type 业务标识
     */
    private String bizType;

    /**
     * cache uid
     */
    private CachedUidGenerator cachedUidGenerator = new CachedUidGenerator();

    public static class CachedUidGenerator {
        /**
         * RingBuffer size扩容参数, 可提高UID生成的吞吐量, 默认:3
         */
        private int boostPower = 3;
        /**
         * 指定何时向RingBuffer中填充UID, 取值为百分比(0, 100), 默认为50
         */
        private int paddingFactor = 50;

        /**
         * 另外一种RingBuffer填充时机
         */
        private int scheduleInterval = 0;

        public int getBoostPower() {
            return boostPower;
        }

        public void setBoostPower(int boostPower) {
            this.boostPower = boostPower;
        }

        public int getPaddingFactor() {
            return paddingFactor;
        }

        public void setPaddingFactor(int paddingFactor) {
            this.paddingFactor = paddingFactor;
        }

        public int getScheduleInterval() {
            return scheduleInterval;
        }

        public void setScheduleInterval(int scheduleInterval) {
            this.scheduleInterval = scheduleInterval;
        }

        @Override
        public String toString() {
            return "CachedUidGenerator{" +
                    "boostPower=" + boostPower +
                    ", paddingFactor=" + paddingFactor +
                    ", scheduleInterval=" + scheduleInterval +
                    '}';
        }
    }


    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public String getEpochStr() {
        return epochStr;
    }

    public void setEpochStr(String epochStr) {
        this.epochStr = epochStr;
    }

    public int getTimeBits() {
        return timeBits;
    }

    public void setTimeBits(int timeBits) {
        this.timeBits = timeBits;
    }

    public int getWorkerBits() {
        return workerBits;
    }

    public void setWorkerBits(int workerBits) {
        this.workerBits = workerBits;
    }

    public int getSeqBits() {
        return seqBits;
    }

    public void setSeqBits(int seqBits) {
        this.seqBits = seqBits;
    }

    public CachedUidGenerator getCachedUidGenerator() {
        return cachedUidGenerator;
    }

    public void setCachedUidGenerator(CachedUidGenerator cachedUidGenerator) {
        this.cachedUidGenerator = cachedUidGenerator;
    }

    public String getBizType() {
        return bizType;
    }

    public void setBizType(String bizType) {
        this.bizType = bizType;
    }

    @Override
    public String toString() {
        return "UIdProperties{" +
                "enable=" + enable +
                ", epochStr='" + epochStr + '\'' +
                ", timeBits=" + timeBits +
                ", workerBits=" + workerBits +
                ", seqBits=" + seqBits +
                ", bizType='" + bizType + '\'' +
                ", cachedUidGenerator=" + cachedUidGenerator +
                '}';
    }
}
